#include "ReadIndex.h"



#ifdef PRELOAD_INVIDX

bool ReadIndex::next(invidx& idx) {

	if (cur == cur_end) return false;

	idx = vInvIdx[cur];
	cur++;

	return true;
}

#else

bool ReadIndex::begin(int offset, int df) {

	fseek(invidx_fp,offset*invidx_size,SEEK_SET);
	invidx_df=df;
	return true;
}

bool ReadIndex::next(invidx& idx) {
	if (invidx_df==0) return false;

	char buf[255];
	fgets(buf,255,invidx_fp);

	char id[20]={0}, tf[20]={0};
	strncpy(id,buf+6,5);
	idx.doc_id=atoi(id);
	strncpy(tf,buf+11,3);
	idx.tf=atoi(tf);

	invidx_df--;
	return true;
}
#endif


int ReadIndex::GetTermID(const char* term) {
	return invTerm[term];
}

